﻿@{
    ViewBag.Title = "SysGoodsList";
}
@section scripts
{
    <style>
        img {
            border:2px solid #808080;
        }
    </style> 
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
}
   <div class="mini-splitter" style="width:100%;height:100%;">

    <div showcollapseButton="true">
        @Html.Partial("~/Views/Modular/ToolBarBase.cshtml")
        @Html.Partial("~/Views/Modular/SearchInfo.cshtml")
        <div class="mini-fit" >
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                    borderStyle="border:1;" url="GetSysGoodsList"
                    allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"  
                    onrowdblclick="modify" onrowclick="selected"  sortMode="client">
                <div property="columns">
                    <div type="checkcolumn" >选行</div>
                    <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                    <div field="FClassName" name="FClassName" width="100" headeralign="center" allowsort="true">分类</div>
                    <div field="FCode" name="FCode" width="150" headeralign="center" allowsort="true">商品条码</div>
                    <div field="FName" name="FName" width="150" headeralign="center" allowsort="true">商品名称</div>
                    <div field="FSpec" name="FSpec" width="90" headeralign="center" allowsort="true">规格</div>
                    <div field="FUnitName" name="FUnitName" width="70" headeralign="center" allowsort="true">单位</div>
                    <div field="FConvert" name="FConvert" width="70" headeralign="center" allowsort="true">内装数</div>
                    <div field="FPurPrice" name="FPurPrice" width="70" numberFormat="#,0.00"  align="right"  headeralign="center" allowsort="true">进价</div>
                    <div field="FPosPrice" name="FPosPrice" width="70" numberFormat="#,0.00"  align="right"  headeralign="center" allowsort="true">零售价</div>
                    <div field="FSpelling" name="FSpelling" width="70" headeralign="center" allowsort="true">助记码</div>
                    <div field="FMakeIn" name="FMakeIn" width="100" headeralign="center" allowsort="true">产地</div>
                </div>
            </div>
        </div>
      </div>

      <div size="300" showcollapseButton="true">
            <table style= "width:100%; height:700px;margin-top:0px;">
                <tr>
                    <td class="auto-style1">
                        <div id="div_imglist" style="margin-left:30px;">
                              <img id="Image0" src="~/Content/Images/PImage.jpg" Width="120" height="120" /> 
                              <img id="Image1" src="~/Content/Images/PImage.jpg" Width="120" height="120" /> 
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="auto-style1">
                        <div id="div_imglist1" style="margin-left:30px;">
                              <img id="Image2" src="~/Content/Images/PImage.jpg" Width="120" height="120" /> 
                              <img id="Image3" src="~/Content/Images/PImage.jpg" Width="120" height="120" /> 
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="auto-style1">
                        <div id="div_imglist2" style="margin-left:30px;">
                                <img id="Image4" src="~/Content/Images/PImage.jpg" Width="120" height="120" />
                                <img id="Image5" src="~/Content/Images/PImage.jpg" Width="120" height="120" /> 
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="auto-style1">
                        <div id="div_imglist3" style="margin-left:30px;">
                                <img id="Image6" src="~/Content/Images/PImage.jpg" Width="120" height="120" /> 
                                <img id="Image7" src="~/Content/Images/PImage.jpg" Width="120" height="120" /> 
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div  id="div_imglist4" style="margin-left:30px;">
                                <img id="Image8" src="~/Content/Images/PImage.jpg" Width="120" height="120" /> 
                                <img id="Image9" src="~/Content/Images/PImage.jpg" Width="120" height="120" />
                        </div>
                    </td>
                </tr>
            </table>
      </div>
    </div>
                        <input id="ImagFile0" name="ImagFile0" class="mini-hidden" />  
                        <input id="ImagFile1" name="ImagFile1" class="mini-hidden" />  
                        <input id="ImagFile2" name="ImagFile2" class="mini-hidden" />  
                        <input id="ImagFile3" name="ImagFile3" class="mini-hidden" />  
                        <input id="ImagFile4" name="ImagFile4" class="mini-hidden" />
                        <input id="ImagFile5" name="ImagFile5" class="mini-hidden" />  
                        <input id="ImagFile6" name="ImagFile6" class="mini-hidden" />  
                        <input id="ImagFile7" name="ImagFile7" class="mini-hidden" />  
                        <input id="ImagFile8" name="ImagFile8" class="mini-hidden" />  
                        <input id="ImagFile9" name="ImagFile9" class="mini-hidden" />                        

<script>
    //通用shown自动调用些方式
        mini.parse();
    function FormShown() {
        LoadListData();
    }

    function ImageFilePath(url) {
        var result = "";
        $.ajax({
            url: "/GetItem/GetImageFilePath",
            data: { Url: url },
            type: "post",
            async: false,
            success: function (data) {
                result = data;
            },
            failure: function () {
                result = "";
            },
            error: function (jqXHR, textStatus, errorThrown) {
                return "";
            }
        });
        return result;
    }

    function selected() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            $.post("GetSysGood", { json: "[{'FItemID':'" + row.FItemID + "','mSystemAppID':''}]" }, function (data) {
                var mdata = mini.decode(data);
                if (mdata.data.length == 0)
                    return;
                if (mdata.data[0].FProImage != "" && mdata.data[0].FProImage != null) {
                    var ImgFile = mdata.data[0].FProImage.split("$");
                    if (ImgFile.length > 0) {
                        for (var i = 0; i < 10; i++) {
                            $("#Image" + i).attr("src", "/Content/Images/PImage.jpg");
                            mini.getbyName("ImagFile" + i).setValue("");
                        }
                        $.each(ImgFile, function (key, item) {
                            if (item != "") {
                                item = ImageFilePath(item);
                                $("#Image" + key).attr("src", item);
                                mini.getbyName("ImagFile" + key).setValue(item);
                            }
                        });
                    }
                }
                else {
                    for(var i=0;i<10;i++){
                            $("#Image" + i).attr("src", "/Content/Images/PImage.jpg");
                            mini.getbyName("ImagFile" + i).setValue("");
                        }
                }
            });
        }
    }

    //修改资料
    function modify() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/SysGoods/SysGoodsInfo",
                title: "商品资料", width: 700, height: 470,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", FItemID: row.FItemID, FClassID: row.FClassID };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    LoadListData();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    //加载资料列表
    function LoadListData() {
        var sSystemAppID = "";//parent.window.getSystemAppID();
            var classid = "0";//node.FItemID;
            var json = "[{";
            json = json + "'FSystemAppID':" + "'" + sSystemAppID + "',";
            json = json + "'mClassID':" + "'" + classid + "',";
            json = json + "'FNumber':" + "'" + mini.getbyName("FSearchKey").getValue() + "'";
            json = json + "}]";
            var grid = mini.get("datagrid1");//==
            grid.load({ mjson: json });
    }

    ///增加资料
    function newBill() {
        var uID = "";//parent.window.getSystemAppID();
        mini.open({
            url: "/SysGoods/SysGoodsInfo",
            title: "商品资料", width: 700, height: 470,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", FItemID: "0", FClassID: "" /*node.FItemID*/, FClassNumber: ""/*node.FNumber*/, FClassName: "" /*node.FName*/ };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                var grid = mini.get("datagrid1");
                grid.reload();
            }
        });
    }

    //搜索资料列表
    function search() {
        LoadListData();
    }
    //刷新
    function refresh() {
        mini.getbyName("FSearchKey").setValue('');
        LoadListData();
    }

    function setkeyPress() {
        if (event.keyCode == 13) {
            search();
        }
    }

    //删除资料
    function removeInfo() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        var FSystemAppID = parent.window.getSystemAppID();
        if (row) {
            mini.confirm("确定要删除选中的记录吗？", "提示",
                function (action) {
                    if (action == "ok") {
                        var json = "{'FItemID':'" + row.FItemID + "'}";
                        $.post("RemoveSysInfo", { json: json, mSystemAppID: FSystemAppID }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                grid.reload();
                            }
                            else {
                                mini.alert("异常:" + ret.error);
                            }
                        });
                    }
                });
        } else {
            mini.alert("请选中一条记录");
        }
    }
</script>
